using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Media;
using System.Windows.Shapes;
using System.Windows.Data;
using System.Windows.Controls;
using Commons;
using WPFBPMN.Utils;

namespace CustomControls
{


    public struct StartMouseDownInformation
    {
        public Point StartPoint;
        public double Width;
        public double Height;

    }

    public class BPMNEvent : BPMNShape
    {
        EventType eventType = EventType.None;
        public EventType EventType
        {
            get
            {
                return eventType;
            }
            set
            {
                eventType = value;
            }
        }
        public BPMNEvent(BPMNShape parent, List<string> additionalArguments)
            : base(parent)
        {
            eventType =(EventType) Enum.Parse(typeof(EventType), additionalArguments[0]);
            LockSizeRatio = true;
            Shape = new Ellipse();
        }
    }

    public class BPMNGateway : BPMNShape
    {
        GatewayType gatewayType = GatewayType.None;
        public GatewayType GatewayType
        {
            get
            {
                return gatewayType;
            }
            set
            {
                gatewayType = value;
            }
        }
        public BPMNGateway(BPMNShape parent, List<string> additionalArguments)
            : base(parent)
        {
            BrushKey = "BrushGateway" + additionalArguments[0];
            BPMNShapeType = ShapeType.BPMNGateway;
            gatewayType = (GatewayType)Enum.Parse(typeof(GatewayType), additionalArguments[0]);
            LockSizeRatio = true;
            ShapeDefaultSize = new Size(60, 60);
            Path path = new Path();
            PathFigure figure = new PathFigure();
            PathSegment segment = new LineSegment(new Point(ShapeDefaultSize.Width / 2, 0), true);
            figure.Segments.Add(segment);
            segment = new LineSegment(new Point(ShapeDefaultSize.Width, ShapeDefaultSize.Height / 2), true);
            figure.Segments.Add(segment);
            segment = new LineSegment(new Point(ShapeDefaultSize.Width / 2, ShapeDefaultSize.Height), true);
            figure.Segments.Add(segment);
            segment = new LineSegment(new Point(0, ShapeDefaultSize.Height / 2), true);
            figure.Segments.Add(segment);
            segment = new LineSegment(new Point(ShapeDefaultSize.Width / 2, 0), true);
            figure.Segments.Add(segment);
            PathFigure[] figures ={ figure };
            path.Data = new PathGeometry(figures);
            path.Stretch = Stretch.Fill;
            Shape = path;

        }
    }

    public class BPMNActivity : BPMNShape
    {
        public BPMNActivity(BPMNShape parent,List<string> additionalParameters)
            : base(parent)
        {
            ShapeDefaultSize = new Size(150, 100);
            BPMNShapeType = ShapeType.BPMNActivity;
            Shape = new Rectangle();
            Shape.Width = 40;
            Shape.Height = 40;
            Shape.Fill = Brushes.White;
        }
        public override void BPMNInitialize()
        {
            base.BPMNInitialize();
            Rectangle border = new Rectangle();
            border.StrokeThickness = 1;
            border.StrokeLineJoin = PenLineJoin.Round;
            border.Stroke = Brushes.Black;
            Canvas.SetTop(border, 0);
            Canvas.SetLeft(border, 0);

            Binding binding = new Binding();
            binding.Source = this;
            binding.Path = new PropertyPath(BPMNShape.WidthProperty);
            border.SetBinding(Rectangle.WidthProperty, binding);


            binding = new Binding();
            binding.Source = this;
            binding.Path = new PropertyPath(BPMNShape.HeightProperty);
            border.SetBinding(Rectangle.HeightProperty, binding);

            (this as Canvas).Children.Add(border);
            border.IsHitTestVisible = false;
        }
    }

    public class BPMNTask : BPMNActivity
    {
        public BPMNTask(BPMNShape parent, List<string> additionalParameters)
            : base(parent, additionalParameters)
        {

        }
    }


    #region BPMNEventStart

    public class BPMNEventStart : BPMNEvent
    {

        public BPMNEventStart(BPMNShape parent,List<string> additionalArguments)
            : base(parent,additionalArguments)
        {
            BrushKey = "BrushEventStart" + additionalArguments[0];
            BPMNShapeType = ShapeType.BPMNEventStart;
        }
    }

    #endregion

    #region BPMNEventIntermediate

    public class BPMNEventIntermediate : BPMNEvent
    {
        public BPMNEventIntermediate(BPMNShape parent, List<string> additionalArguments)
            : base(parent,additionalArguments)
        {
            BrushKey = "BrushEventIntermediate" + additionalArguments[0];
            BPMNShapeType = ShapeType.BPMNEventIntermediate;
        }
    }

    #endregion

    #region BPMNEventEnd

    public class BPMNEventEnd : BPMNEvent
    {
        public BPMNEventEnd(BPMNShape parent, List<string> additionalArguments)
            : base(parent,additionalArguments)
        {
            BrushKey = "BrushEventEnd" + additionalArguments[0];
            BPMNShapeType = ShapeType.BPMNEventEnd;
        }
    }

    #endregion

}
